06. Login to the Instance
Login to the Instance
After launch, your instance may take a few minutes to initialize.
Once you see “2/2 checks passed” on the EC2 Management Console, your instance is ready for you to log in.
Note the "IPv4 Public IP" address (in the format of “X.X.X.X”) on the EC2 Dashboard.
From a terminal, navigate to the location where you stored your .pem file. (For example, if you put your .pem file on your Desktop,
cd ~/Desktop/
will move you to the correct directory.)
Type
ssh -i YourKeyName.pem ubuntu@X.X.X.X
, where:
-
X.X.X.X
is the IPv4 Public IP found in AWS, and -
YourKeyName.pem
is the name of your .pem file.
Note that if you've used a different AMI or specified a username,
ubuntu
will be replaced with the username, such as
ec2-user
for some Amazon AMI's. You would then instead enter
ssh -i YourKeyName.pem ec2-user@X.X.X.X
Configure Jupyter notebook settings
In your instance, in order to create a config file for your Jupyter notebook settings, type:
jupyter notebook --generate-config
.
Then, to change the IP address config setting for notebooks (this is just a fancy one-line command to perform an exact string match replacement; you could do the same thing manually using vi/vim/nano/etc.), type:
sed -ie "s/#c.NotebookApp.ip = 'localhost'/#c.NotebookApp.ip = '*'/g" ~/.jupyter/jupyter_notebook_config.py
Test the Instance
Make sure everything is working properly by verifying that the instance can run a notebook.
On the EC2 instance
-
Clone a GitHub repository
-
git clone https://github.com/udacity/deep-learning-v2-pytorch.git
-
-
Enter the repo directory, and the CNN subdirectory
-
cd deep-learning-pytorch
-
cd cnn-content
-
-
Install the requirements
-
sudo python3 -m pip install -r requirements.txt
-
-
Start Jupyter notebook
-
jupyter notebook --ip=0.0.0.0 --no-browser
-
From your local machine
-
You will need the token generated by your jupyter notebook to access it. On your instance terminal, there will be the following line:
Copy/paste this URL into your browser when you connect for the first time, to login with a token:
. Copy everything starting with the:8888/?token=
. -
Access the Jupyter notebook index from your web browser by visiting:
X.X.X.X:8888/?token=...
(where X.X.X.X is the IP address of your EC2 instance and everything starting with:8888/?token=
is what you just copied). - Click on a folder, like "mnist", to enter it and select a notebook, such as the "mnist_mlp.ipynb" notebook.
- Run each cell in the notebook.
For some notebooks, you should see a marked decrease in training time when compared to running the same cells using a typical CPU!
NOTE: Windows users may prefer connecting via the GUI utility PuTTY, by following these instructions .
Important: Cost
**From this point on, AWS will charge you for a running an EC2 instance. ** You can find the details on the EC2 On-Demand Pricing page .
Most importantly, remember to
stop
(i.e. shutdown) your instances when you are not using them. Otherwise, your instances might run for a day or a week or a month without you remembering, and you’ll wind up with a large bill!
AWS charges primarily for running instances, so most of the charges will cease once you stop the instance. However, there are smaller storage charges that continue to accrue until you “terminate” (i.e. delete) the instance.